<?php
  require("utilities.php");
  if($_GET['delete']){
    $sid = (int)$_GET['delete'];
    mysql_query("Delete From student where SID = {$sid}");
    header("Location: database.php");
    exit;
  }
  if($_POST){
    $info=array();
    $info['Fname'] = mysql_real_escape_string($_POST['Fname']);
    $info['Lname'] = mysql_real_escape_string($_POST['Lname']);
    $info['Bday']  = mysql_real_escape_string($_POST['Bday']);
    mysql_query("INSERT into student (Fname,Lname,Bday) VALUES ('{$info['Fname']}','{$info['Lname']}','{$info['Bday']}');");
    header("Location: database.php");
    exit;
  }
?>
<!--- um...layout sturf -->
<html>
  <head> 
    <title> New Layout! </title> 
    <link rel="stylesheet" href="main.css" type="text/css"/>
  </head>
  <body>
    <!-- Main Layouy -->
    <div id="container">
      <!-- TITLE -->
      <div id="title">
        <?php
          echo "Hello, Zygomatic World!";
        ?>
      </div>
      <!-- NAVIGATION --> 
      <div id="navigation">
        <ul id="navList">
          <li><a href="http://ix.cs.uoregon.edu/~trevor">Home</a></li>
          <li>Classes</li>
          <li>Resum&eacute;<li>
          <li><a href="http://www.pandemoniumsyndicate.deviantart.com">Gallery</a></li>
          <li><a href="http://ix.cs.uoregon.edu/~trevor/database.php">DataBase Testbed</a></li>
        </ul> 
      </div>
      <!-- CONTENT -->
      <div id="content"> 
        <table cellpadding="4" cellspacing="0" id="testDataBase">
          <tr>
            <th> First Name </th>
            <th> Last Name </th>
            <th> BirthDay </th>
            <th> Delete? </th>
          </tr>
          <?php
            $query = mysql_query("SELECT * FROM student WHERE 1 ORDER BY Lname asc, Fname asc");
            $count = 0;
            while($row = mysql_fetch_assoc($query)){
              $style = ($count%2 == 0) ? 'row1' : 'row2';
              echo "<tr class=\"{$style}\">\n";
              echo "<td>{$row['Fname']}</td>\n";
              echo "<td>{$row['Lname']}</td>\n";
              echo "<td>{$row['Bday']}</td>\n";
              echo "<td><a href= \"?delete={$row[SID]}\">Delete? </a></td>";
              echo "</tr>\n";
              $count++;
            }
          ?> 
        </table>
        <form name="form1" method="post" action="newLayout.php">
        <table cellpadding="4" cellspacing="0">
          <tr>
            <th> First Name </th>
            <th> Last Name </th>
            <th> BirthDay </th> 
          </tr>
          <tr>
            <td><input type="text" name="Fname" size="10" /></td>
            <td><input type="text" name="Lname" size="10" /></td>
            <td><input type="text" name="Bday" size="10" /></td>
          </tr>
        </table>
        <p align="center"><input type="submit" value="Insert"/></p>
        </form>
      </div>
    </div>
  </body>
</html> 

  
